<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>订单退货不良品入仓</title>
    <link rel="stylesheet" href="/sb/stock.css"/>
    <link rel="stylesheet" href="/layui/css/layui.css" media="all">
    <script src="/js/jquery-3.3.1.min.js"></script>
    <script src="/layui/layui.js"></script>

</head>
<body>
<div class="sp-wrapper">
    <h2 class="sp-title"><span>订单退货不良品入仓</span></h2>
    <div class="sp-tool">
        <span class="fl">
            <b>单据编号：[[${lists.orderNum}]]</b>
        </span>
        <span class="fr">
            <i id="save" class="save" >确认入库</i>
        </span>
    </div>
    <div class="sp-table">
        <form id="stockInForm" action="/order_return/upd_bad_stock" method="post">
        <table>
            <thead>
            <tr>
                <th>序号</th>
                <th>商品</th>
                <th>规格</th>
                <th>SKU</th>
                <th>数量</th>
                <th>已入库数量</th>
                <!--<th>入库仓位</th>-->
                <th>入库数量</th>
            </tr>
            </thead>
            <tbody id="sp-data">
            <tr th:each="item:${lists.items}">
                <td th:text="${itemStat.index + 1}"></td>
                <td th:text="${item.goodsName}">
                </td>
                <td>
                    颜色：<i th:text="${item.colorValue}"></i>&nbsp;尺码：<i th:text="${item.sizeValue}"></i>
                </td>
                <td th:text="${item.skuNumber}"></td>
                <td th:text="${item.quantity}">200</td>
                <td th:text="${item.badQuantity+item.inQuantity}">0</td>
                <!--<td>
                    <input type="hidden" class="locationNumber" name="locationNumber" value="0" autocomplete="off" readonly/>
                </td>-->
                <td>
                    <input type="hidden" class="locationId" name="locationId"  value="0" />
                    <input type="hidden" name="goodsId"  th:value="${item.goodsId}" />
                    <input type="hidden" name="itemId"  th:value="${item.id}" />
                    <input type="hidden" name="specNumber"  th:value="${item.skuNumber}" />
                    <input type="hidden" name="billNo" th:value="${lists.orderNum}">
                    <input type="hidden" name="returnId" th:value="${lists.id}">
                    <input type="hidden" name="maxQuantity"  th:value="${item.quantity - item.inQuantity - item.badQuantity}" />
                    <input type="number" name="quantity" class="quantity" autocomplete="off" placeholder="请入库数量"/>
                </td>
            </tr>

            </tbody>
        </table>
        </form>
    </div>
    <script>
        $(function () {
            // 保存
            $('#save').click(function () {
                var btnObj = $(this);
                var hasClick = $(this).hasClass("hasClick");
                // alert(hasClick);
                if(hasClick == true){
                    alert("保存中，请勿重复点击")
                    return ;
                }
                btnObj.addClass("hasClick");
                var returnResult = true;//是否有错误数据

                var quantity =document.getElementsByName("quantity");
                var specNumber =document.getElementsByName("specNumber");
                var maxQuantity =document.getElementsByName("maxQuantity");
                for (var i =0 ; i < specNumber.length ; i++){
                    if (quantity[i].value == ""){
                        btnObj.removeClass("hasClick");
                        alert("请输入入库数量");
                        $("input[name^='quantity']").eq(i).focus();
                        returnResult = false;
                        return;
                    } else {
                        if (quantity[i].value > maxQuantity[i].value){
                            btnObj.removeClass("hasClick");
                            alert("超出可入库数量");
                            $("input[name^='quantity']").eq(i).focus();
                            returnResult = false;
                            return;
                        }
                    }
                }

                if (returnResult == false) {
                    btnObj.removeClass("hasClick");
                    return false;
                }
                $("#stockInForm").submit();
               /* var data = {
                    infos:stockInItems
                };

                //检查入库仓位等校验
                $.ajax({
                    url: "/order_return/bad_stock_check",
                    type: "POST",
                    dataType: "json",
                    contentType: "application/json",
                    data: JSON.stringify(data),
                    success: function (res) {
                        btnObj.removeClass("hasClick");
                        if (res.code == 0) {
                            $("#stockInForm").submit();
                        } else {
                            alert(res.msg);
                        }
                    }
                });
                return false;*/
            });
        });
    </script>


</div>
</body>
</html>